// pages/staff/index.js
const http = require('../../utils/http.js')
const config = require('../../config.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    manList: [],    //员工信息列表
    pages: 1,     //当前页数
    hasNextPage: true,  //是否还有下一页
    detail: {},   //活动详情
    imgs: '',   //活动详情图片
    activityId:'',  //活动id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var activityId = options.id
    this.setData({
      activityId
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getPlayData()
  },

  /**
   * 获取员工数据
   */
  getPlayData: function() {
    var that = this
    var data = {
      campaignId: that.data.activityId,
      limit: app.globalData.limit,
      page: that.data.pages
    }
    http.httpReq(config.playData,"GET",data,function(res){
      var detail = res.data.detail
      var manList = app.cutImg(res.data.list.list)
      var imgs = app.picCut(res.data.detail.imgs)
      manList.forEach(function(el){
        that.data.manList.push(el)
      })
      that.setData({
        imgs,
        detail,
        hasNextPage: res.data.list.hasNextPage,
        manList: that.data.manList,
        pages: that.data.pages + 1
      })
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (!that.data.hasNextPage) {
      wx.showToast({
        title: '没有更多了',
        icon: 'none'
      })
      return
    }
    that.getPlayData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /**
   * 点击参赛人，进入投票
   */
  goVoteTap: function(e) {
    //获取参赛人ID
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../vote/index?manId='+ id,
    })
  }
})